home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / arphdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  1.3 KB  |  60 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "arp.h"
  4.  
  5. /* Copy a host format arp structure into mbuf for transmission */
  6. struct mbuf *
  7. htonarp(arp)
  8. struct arp *arp;
  9. {
  10.     struct mbuf *bp;
  11.     char *buf;
  12.  
  13.     if(arp == (struct arp *)NULL)
  14.         return NULLBUF;
  15.  
  16.     bp = ambufw(ARPLEN + (2 * uchar(arp->hwalen)));
  17.  
  18.     buf = bp->data;
  19.     buf = put16(buf,arp->hardware);
  20.     buf = put16(buf,arp->protocol);
  21.     *buf++ = arp->hwalen;
  22.     *buf++ = arp->pralen;
  23.     buf = put16(buf,arp->opcode);
  24.     memcpy(buf,arp->shwaddr,(int16)uchar(arp->hwalen));
  25.     buf += arp->hwalen;
  26.     buf = put32(buf,arp->sprotaddr);
  27.     memcpy(buf,arp->thwaddr,(int16)uchar(arp->hwalen));
  28.     buf += arp->hwalen;
  29.     buf = put32(buf,arp->tprotaddr);
  30.  
  31.     bp->cnt = buf - bp->data;
  32.     return bp;
  33. }
  34.  
  35. /* Convert an incoming ARP packet into a host-format structure */
  36. int
  37. ntoharp(arp,bpp)
  38. struct arp *arp;
  39. struct mbuf **bpp;
  40. {
  41.     if(arp == (struct arp *)NULL || bpp == NULLBUFP)
  42.         return -1;
  43.  
  44.     arp->hardware = pull16(bpp);
  45.     arp->protocol = pull16(bpp);
  46.     arp->hwalen = PULLCHAR(bpp);
  47.     arp->pralen = PULLCHAR(bpp);
  48.     arp->opcode = pull16(bpp);
  49.     pullup(bpp,arp->shwaddr,(int16)uchar(arp->hwalen));
  50.     arp->sprotaddr = pull32(bpp);
  51.     pullup(bpp,arp->thwaddr,(int16)uchar(arp->hwalen));
  52.     arp->tprotaddr = pull32(bpp);
  53.  
  54.     /* Get rid of anything left over */
  55.     free_p(*bpp);
  56.     *bpp = NULLBUF;
  57.     return 0;
  58. }
  59.  
  60.